{template 'web/_header'}
{template 'web/shop/tabs'}
{if $op== 'display'}
<form action="" method="post">
    <div class="panel panel-default">
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead class="navbar-inner">
                    <tr>
                        <th style='width:5%;'>ID</th>					
                        <th style='width:5%;'>活动标题</th>
                        <th style='width:10%;'>满减优惠</th>
                        <th style='width:10%;'>活动时间</th>
                        <th style='width:5%;'>创建时间</th>
                        <th style='width:5%;'>状态</th>
                        <th style='width:5%;'>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $list $row}
                    <tr>
                        <td>{$row['id']}</td>
                        <td>{$row['title']}</td>
                        <td>{$row['em_id']}</td>
                        <td>{$row['starttime']}~{$row['endtime']}</td>
                        <td>{$row['createtime']}</td>
                        <td>
                            {if $row['status']==1}
                            <span class='label label-success' onclick="isshow(this, {$row['id']})">显示</span>
                            {else}
                            <span class='label label-danger' onclick="isshow(this, {$row['id']})">隐藏</span>
                            {/if}
                        </td>
                        <td>
                            <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>
                            <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'activity_delete', 'id' => $row['id']))}"class="btn btn-default btn-sm" onclick="return confirm('确认删除此活动?')" title="删除"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    <tr>
                        <td colspan='1'>
                            <a class='btn btn-default' href="{php echo $this->createWebUrl('shop/enoughmoney',array('op'=>'post'))}"><i class='fa fa-plus'></i>添加活动</a>
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        </td>
                    </tr>
                </tbody>
            </table>
            {$pager}
        </div>
    </div>
</form>
<script>
            require(['bootstrap'], function($) {
            $('.btn').hover(function() {
            $(this).tooltip('show');
            }, function() {
            $(this).tooltip('hide');
            });
            });
</script>
<script>
            function isshow(obj, id){
            $(obj).html($(obj).html() + "...");
            $.post("./index.php?c=site&a=entry&p=enoughmoney&op=activity_status_set&do=shop&m=ewei_shop", {id:id}, function(d){
            $(obj).html($(obj).html().replace("...", ""));
            if (d.result == 1){
                    $(obj).html(d.status == '1'?'显示':'隐藏');
                    $(obj).attr('class', d.status == 1?"label label-success":"label label-danger");
            }
            }
            , "json"
                    );
            }
</script>
{/if}
{if $op == 'post'}
<div class="main">
    <form  action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <div class="panel panel-default">
            <div class="panel-heading">
                满减活动设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='title' name="title" class="form-control" value="{$activity['title']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择商品</label>
                    <div class="col-sm-9  col-xs-12">
                        <select class="form-control" multiple="multiple" name="goods[]">
                            {if $goods}
                            {loop $goods $li}
                            <option value="{$li['id']}" {if $li['goodsid_select'] == '1'}selected{/if}>{$li['title']}</option>
                            {/loop}
                            {/if}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">勾选满减优惠</label>
                    <div class="col-sm-9 col-xs-12">
                        {loop $manjianes $row}
                        <label class="checkbox-inline">
                            <input type="checkbox" name="em_id[]" value="{$row['id']}" {if $row['em_select'] == '1'}checked{/if}>满{$row['enoughmoney']}元减{$row['enoughdeduct']}元
                        </label>
                        {/loop}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动时间</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d  H:i', $endtime)),true);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=1' {if $activity['status']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=0' {if $activity['status']==0}checked{/if} /> 否
                        </label>
                    </div>
                </div>
                <div class="form-group"></div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                        <input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表" class="btn btn-default" />
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
{/if}
{if $op == 'set_list'}
<form action="" method="post">
    <div class="panel panel-default">
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead class="navbar-inner">
                    <tr>
                        <th>ID</th>
                        <th>满金额</th>
                        <th>优惠金额</th>
                        <th>状态</th>
                        <th >操作</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $list $row}
                    <tr>
                        <td>{$row['id']}</td>
                        <td>{$row['enoughmoney']}元</td>
                        <td>{$row['enoughdeduct']}元</td>
                        <td>
                            {if $row['status']==1}
                            <span class='label label-success' onclick="isshow(this, {$row['id']})">显示</span>
                            {else}
                            <span class='label label-danger'  onclick="isshow(this, {$row['id']})">隐藏</span>
                            {/if}
                        </td>
                        <td style="text-align:left;">
                            <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'set_post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>
                            <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'delete', 'id' => $row['id']))}"class="btn btn-default btn-sm" onclick="return confirm('确认删除?')" title="删除"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    <tr>
                        <td colspan='1'>
                            <a class='btn btn-default' href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'set_post'))}"><i class='fa fa-plus'></i>添加满减优惠</a>
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        </td>
                    </tr>
                </tbody>
            </table>
            {$pager}
        </div>
    </div>
</form>
<script>
            require(['bootstrap'], function($) {
            $('.btn').hover(function() {
            $(this).tooltip('show');
            }, function() {
            $(this).tooltip('hide');
            });
            });</script>
<script>
            function isshow(obj, id){
            $(obj).html($(obj).html() + "...");
                    $.post("./index.php?c=site&a=entry&p=enoughmoney&op=status_set&do=shop&m=ewei_shop", {id:id}, function(d){
                    $(obj).html($(obj).html().replace("...", ""));
                            if (d.result == 1){
                    $(obj).html(d.status == '1'?'显示':'隐藏');
                            $(obj).attr('class', d.status == 1?"label label-success":"label label-danger");
                    }
                    }
                    , "json"
                            );
            }
</script>
{/if}
{if $op=="set_post"}
<div class="main">
    <form   method="post" class="form-horizontal form" enctype="multipart/form-data">
        <div class="panel panel-default">
            <div class="panel-heading">
                满减设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">满金额</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='title' name="enoughmoney" class="form-control" value="{$enough['enoughmoney']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">优惠金额</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="enoughdeduct" class="form-control" value="{$enough['enoughdeduct']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=1' {if $enough['status']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=0' {if $enough['status']==0}checked{/if} /> 否
                        </label>
                    </div>
                </div>
                <div class="form-group"></div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                        <input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表" class="btn btn-default" />
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
{/if}
{template 'web/_footer'}